package com.cat.greedyAlgorithm;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximize-greatness-of-an-array/
 * @create 2025/8/23 10:29
 * @since JDK17
 */

public class Solution20 {
    public int maximizeGreatness(int[] nums) {
        int ans = 0, n = nums.length;
        Arrays.sort(nums);
        for (int i = 0, j = 1; i < n; i++) {
            while (j < n && nums[j] <= nums[i]) {
                j++;
            }
            if (j == n) {
                break;
            } else {
                j++;
                ans++;
            }
        }

        return ans;
    }
}
